package com.example.springbatch_step_stop;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.stereotype.Component;

/**
 * Step监听器
 */
@Component(value = "myStepListener")
public class StopStepListener implements StepExecutionListener {
    @Override
    public void beforeStep(StepExecution stepExecution) {

    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        if (ResouceCount.readCount != ResouceCount.totalCount){
            return ExitStatus.STOPPED;
        }
        return stepExecution.getExitStatus();
    }
}
